package com.cande.loki.exercise.algorithm.od;


import java.util.*;

/**
 *  英文输入法提示
 */
public class EnglishSuggest {
    public static void main(String[] args) {

        System.out.println("input str");
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();

        System.out.println("input pre");
        Scanner scanner1 = new Scanner(System.in);
        String prefix = scanner1.nextLine();

        HashSet<String> setStr = new HashSet<>();
        String[] strArr = str.split("[\\s.,!?;]+");

        for (String word : strArr) {
            if (!word.isEmpty()) {
                setStr.add(word);
            }
        }

        // 将 Set 转换为 List 并按字典序排序
        List<String> wordsList = new ArrayList<>(setStr);
        Collections.sort(wordsList);

        // 找到符合前缀的单词
        List<String> suggestions = new ArrayList<>();
        for (String word : wordsList) {
            if (word.startsWith(prefix)) {
                suggestions.add(word);
            }
        }

        // 输出结果
        if (suggestions.isEmpty()) {
            System.out.println(prefix);
        } else {
            System.out.println(String.join(" ", suggestions));
        }

        scanner.close();
    }
}
